package com.kxf.rpc.serializer;

import com.kxf.rpc.enumeration.RpcError;
import com.kxf.rpc.exception.RpcException;

/**
 * @author Kxf
 * @create 2021/9/22,0022 16:35
 */
public interface CommonSerialize {

    byte[] serialize(Object object);

    <T> T deSerialize(byte[] bytes, Class<T> clazz);

    int getCode();

    static CommonSerialize getByteCode(int code) {
        switch (code) {
            case 0:
                return new JsonSerializer();
            case 1:
                return new KryoSerializer();
            case 2:
                return new ProtostuffSerializer();
            default:
                throw new RpcException(RpcError.SERIALIZE_NOT_FIND);
        }
    }
}
